<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LINE 1 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-1"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span>
</span><span id="line-3"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">System.Console.Haskeline.Backend.Win32</span><span class="hs-special">(</span><span>
</span><span id="line-4"></span><span>                </span><span class="hs-identifier">win32Term</span><span class="hs-special">,</span><span>
</span><span id="line-5"></span><span>                </span><span class="hs-identifier">win32TermStdin</span><span class="hs-special">,</span><span>
</span><span id="line-6"></span><span>                </span><span class="hs-identifier">fileRunTerm</span><span>
</span><span id="line-7"></span><span>                </span><span class="hs-special">)</span><span class="hs-keyword">where</span><span>
</span><span id="line-8"></span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.IO</span><span>
</span><span id="line-11"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign</span><span>
</span><span id="line-12"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.C</span><span>
</span><span id="line-13"></span><span>
</span><span id="line-14"></span><span class="hs-pragma">{-# LINE 14 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Win32</span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">multiByteToWideChar</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">setConsoleMode</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">getConsoleMode</span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span>
</span><span id="line-16"></span><span class="hs-pragma">{-# LINE 18 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Graphics.Win32.Misc</span><span class="hs-special">(</span><span class="hs-identifier">getStdHandle</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">sTD_OUTPUT_HANDLE</span><span class="hs-special">)</span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.List</span><span class="hs-special">(</span><span class="hs-identifier">intercalate</span><span class="hs-special">)</span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Concurrent.STM</span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Concurrent</span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">throwTo</span><span class="hs-special">)</span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Char</span><span class="hs-special">(</span><span class="hs-identifier">isPrint</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">chr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ord</span><span class="hs-special">)</span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.Maybe</span><span class="hs-special">(</span><span class="hs-identifier">mapMaybe</span><span class="hs-special">)</span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Exception</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">IOException</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">throwTo</span><span class="hs-special">)</span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Monad</span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Control.Monad.Catch</span><span>
</span><span id="line-27"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">MonadThrow</span><span>
</span><span id="line-28"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadCatch</span><span>
</span><span id="line-29"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadMask</span><span>
</span><span id="line-30"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">bracket</span><span>
</span><span id="line-31"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">handle</span><span>
</span><span id="line-32"></span><span>    </span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Console.Haskeline.Key</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Console.Haskeline.Monads</span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Console.Haskeline.LineState</span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Console.Haskeline.Term</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Console.Haskeline.Backend.WCWidth</span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Console.Haskeline.Backend.Win32.Echo</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">hWithoutInputEcho</span><span class="hs-special">)</span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Data.ByteString.Internal</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">createAndTrim</span><span class="hs-special">)</span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">Data.ByteString</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">B</span><span class="hs-cpp">


#include &quot;windows_cconv.h&quot;
</span><span>
</span><span id="line-47"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h ReadConsoleInputW&quot;</span><span> </span><span class="hs-identifier">c_ReadConsoleInput</span><span>
</span><span id="line-48"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h WaitForSingleObject&quot;</span><span> </span><span class="hs-identifier">c_WaitForSingleObject</span><span>
</span><span id="line-51"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">DWORD</span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h GetNumberOfConsoleInputEvents&quot;</span><span>
</span><span id="line-54"></span><span>    </span><span class="hs-identifier">c_GetNumberOfConsoleInputEvents</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-55"></span><span>
</span><span id="line-56"></span><span class="hs-identifier">getNumberOfEvents</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Int</span><span>
</span><span id="line-57"></span><span class="hs-identifier">getNumberOfEvents</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">numEventsPtr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-58"></span><span>    </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;GetNumberOfConsoleInputEvents&quot;</span><span>
</span><span id="line-59"></span><span>        </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_GetNumberOfConsoleInputEvents</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">numEventsPtr</span><span>
</span><span id="line-60"></span><span>    </span><span class="hs-identifier">fmap</span><span> </span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">numEventsPtr</span><span>
</span><span id="line-61"></span><span>
</span><span id="line-62"></span><span class="hs-identifier">getEvent</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">TChan</span><span> </span><span class="hs-identifier">Event</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Event</span><span>
</span><span id="line-63"></span><span class="hs-identifier">getEvent</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">keyEventLoop</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">eventReader</span><span> </span><span class="hs-identifier">h</span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span>
</span><span id="line-65"></span><span class="hs-identifier">eventReader</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Event</span><span class="hs-special">]</span><span>
</span><span id="line-66"></span><span class="hs-identifier">eventReader</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-67"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">waitTime</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">500</span><span> </span><span class="hs-comment">-- milliseconds</span><span>
</span><span id="line-68"></span><span>    </span><span class="hs-identifier">ret</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_WaitForSingleObject</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">waitTime</span><span>
</span><span id="line-69"></span><span>    </span><span class="hs-identifier">yield</span><span> </span><span class="hs-comment">-- otherwise, the above foreign call causes the loop to never</span><span>
</span><span id="line-70"></span><span>          </span><span class="hs-comment">-- respond to the killThread</span><span>
</span><span id="line-71"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">ret</span><span> </span><span class="hs-operator">/=</span><span> </span><span class="hs-special">(</span><span class="hs-number">0</span><span class="hs-special">)</span><span>
</span><span id="line-72"></span><span class="hs-pragma">{-# LINE 72 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-72"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">eventReader</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-73"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-74"></span><span>            </span><span class="hs-identifier">es</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">readEvents</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-75"></span><span>            </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">combineSurrogatePairs</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">mapMaybe</span><span> </span><span class="hs-identifier">processEvent</span><span> </span><span class="hs-identifier">es</span><span>
</span><span id="line-76"></span><span>
</span><span id="line-77"></span><span class="hs-identifier">combineSurrogatePairs</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Event</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Event</span><span class="hs-special">]</span><span>
</span><span id="line-78"></span><span class="hs-identifier">combineSurrogatePairs</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">KeyInput</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Key</span><span> </span><span class="hs-identifier">m1</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">KeyChar</span><span> </span><span class="hs-identifier">c1</span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">KeyInput</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Key</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">KeyChar</span><span> </span><span class="hs-identifier">c2</span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">es</span><span class="hs-special">)</span><span>
</span><span id="line-79"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="hs-number">0xD800</span><span> </span><span class="hs-operator">&lt;=</span><span> </span><span class="hs-identifier">ord</span><span> </span><span class="hs-identifier">c1</span><span> </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">ord</span><span> </span><span class="hs-identifier">c1</span><span> </span><span class="hs-operator">&lt;</span><span> </span><span class="hs-number">0xDC00</span><span> </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-number">0xDC00</span><span> </span><span class="hs-operator">&lt;=</span><span> </span><span class="hs-identifier">ord</span><span> </span><span class="hs-identifier">c2</span><span> </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">ord</span><span> </span><span class="hs-identifier">c2</span><span> </span><span class="hs-operator">&lt;</span><span> </span><span class="hs-number">0xE000</span><span>
</span><span id="line-80"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-identifier">ord</span><span> </span><span class="hs-identifier">c1</span><span> </span><span class="hs-operator">.&amp;.</span><span> </span><span class="hs-number">0x3FF</span><span class="hs-special">)</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">shiftL</span><span class="hs-special">`</span><span> </span><span class="hs-number">10</span><span class="hs-special">)</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ord</span><span> </span><span class="hs-identifier">c2</span><span> </span><span class="hs-operator">.&amp;.</span><span> </span><span class="hs-number">0x3FF</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-number">0x10000</span><span>
</span><span id="line-81"></span><span>      </span><span class="hs-keyword">in</span><span> </span><span class="hs-identifier">KeyInput</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Key</span><span> </span><span class="hs-identifier">m1</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">KeyChar</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">chr</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">combineSurrogatePairs</span><span> </span><span class="hs-identifier">es</span><span>
</span><span id="line-82"></span><span class="hs-identifier">combineSurrogatePairs</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">e</span><span class="hs-glyph">:</span><span class="hs-identifier">es</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">e</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">combineSurrogatePairs</span><span> </span><span class="hs-identifier">es</span><span>
</span><span id="line-83"></span><span class="hs-identifier">combineSurrogatePairs</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-84"></span><span>
</span><span id="line-85"></span><span class="hs-identifier">consoleHandles</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MaybeT</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Handles</span><span>
</span><span id="line-86"></span><span class="hs-identifier">consoleHandles</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-87"></span><span>    </span><span class="hs-identifier">h_in</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">open</span><span> </span><span class="hs-string">&quot;CONIN$&quot;</span><span>
</span><span id="line-88"></span><span>    </span><span class="hs-identifier">h_out</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">open</span><span> </span><span class="hs-string">&quot;CONOUT$&quot;</span><span>
</span><span id="line-89"></span><span>    </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">Handles</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">hIn</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">h_in</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hOut</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">h_out</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-90"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-91"></span><span>   </span><span class="hs-identifier">open</span><span> </span><span class="hs-identifier">file</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">handle</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="hs-identifier">_</span><span class="hs-glyph">::</span><span class="hs-identifier">IOException</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">mzero</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">liftIO</span><span>
</span><span id="line-92"></span><span>                </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">createFile</span><span> </span><span class="hs-identifier">file</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">gENERIC_READ</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-identifier">gENERIC_WRITE</span><span class="hs-special">)</span><span>
</span><span id="line-93"></span><span>                        </span><span class="hs-special">(</span><span class="hs-identifier">fILE_SHARE_READ</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-identifier">fILE_SHARE_WRITE</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-94"></span><span>                        </span><span class="hs-identifier">oPEN_EXISTING</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span>
</span><span id="line-97"></span><span class="hs-identifier">processEvent</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">InputEvent</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">Event</span><span>
</span><span id="line-98"></span><span class="hs-identifier">processEvent</span><span> </span><span class="hs-identifier">KeyEvent</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">keyDown</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">kd</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">unicodeChar</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">virtualKeyCode</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">vc</span><span class="hs-special">,</span><span>
</span><span id="line-99"></span><span>                    </span><span class="hs-identifier">controlKeyState</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">cstate</span><span class="hs-special">}</span><span>
</span><span id="line-100"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">kd</span><span> </span><span class="hs-operator">||</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-identifier">testMod</span><span> </span><span class="hs-special">(</span><span class="hs-number">2</span><span class="hs-special">)</span><span> </span><span class="hs-operator">||</span><span> </span><span class="hs-identifier">vc</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-special">(</span><span class="hs-number">18</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-101"></span><span class="hs-pragma">{-# LINE 101 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-101"></span><span>             </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-operator">/=</span><span> </span><span class="hs-char">'\NUL'</span><span class="hs-special">)</span><span>
</span><span id="line-102"></span><span>      </span><span class="hs-comment">-- Make sure not to ignore Unicode key events! The Unicode character might</span><span>
</span><span id="line-103"></span><span>      </span><span class="hs-comment">-- only be emitted on a keyup event. See also GH issue #54.</span><span>
</span><span id="line-104"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fmap</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">e</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">KeyInput</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Key</span><span> </span><span class="hs-identifier">modifier'</span><span> </span><span class="hs-identifier">e</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-identifier">vc</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">mplus</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">simpleKeyChar</span><span>
</span><span id="line-105"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-106"></span><span>    </span><span class="hs-identifier">simpleKeyChar</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">guard</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">c</span><span> </span><span class="hs-operator">/=</span><span> </span><span class="hs-char">'\NUL'</span><span class="hs-special">)</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">KeyChar</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">)</span><span>
</span><span id="line-107"></span><span>    </span><span class="hs-identifier">testMod</span><span> </span><span class="hs-identifier">ck</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">cstate</span><span> </span><span class="hs-operator">.&amp;.</span><span> </span><span class="hs-identifier">ck</span><span class="hs-special">)</span><span> </span><span class="hs-operator">/=</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-108"></span><span>    </span><span class="hs-identifier">modifier'</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">hasMeta</span><span> </span><span class="hs-identifier">modifier</span><span> </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">hasControl</span><span> </span><span class="hs-identifier">modifier</span><span>
</span><span id="line-109"></span><span>                    </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">noModifier</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">hasShift</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hasShift</span><span> </span><span class="hs-identifier">modifier</span><span class="hs-special">}</span><span>
</span><span id="line-110"></span><span>                    </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">modifier</span><span>
</span><span id="line-111"></span><span>    </span><span class="hs-identifier">modifier</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Modifier</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">hasMeta</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">testMod</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-number">1</span><span class="hs-special">)</span><span>
</span><span id="line-112"></span><span class="hs-pragma">{-# LINE 112 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-112"></span><span>                                        </span><span class="hs-operator">.|.</span><span> </span><span class="hs-special">(</span><span class="hs-number">2</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-113"></span><span class="hs-pragma">{-# LINE 113 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-113"></span><span>                        </span><span class="hs-special">,</span><span class="hs-identifier">hasControl</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">testMod</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-number">4</span><span class="hs-special">)</span><span>
</span><span id="line-114"></span><span class="hs-pragma">{-# LINE 114 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-114"></span><span>                                        </span><span class="hs-operator">.|.</span><span> </span><span class="hs-special">(</span><span class="hs-number">8</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-115"></span><span class="hs-pragma">{-# LINE 115 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-115"></span><span>                                    </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">c</span><span> </span><span class="hs-operator">&gt;</span><span> </span><span class="hs-char">'\NUL'</span><span> </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-operator">&lt;=</span><span> </span><span class="hs-char">'\031'</span><span class="hs-special">)</span><span>
</span><span id="line-116"></span><span>                        </span><span class="hs-special">,</span><span class="hs-identifier">hasShift</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">testMod</span><span> </span><span class="hs-special">(</span><span class="hs-number">16</span><span class="hs-special">)</span><span>
</span><span id="line-117"></span><span class="hs-pragma">{-# LINE 117 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-117"></span><span>                                    </span><span class="hs-operator">&amp;&amp;</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">isPrint</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">)</span><span>
</span><span id="line-118"></span><span>                        </span><span class="hs-special">}</span><span>
</span><span id="line-119"></span><span>
</span><span id="line-120"></span><span class="hs-identifier">processEvent</span><span> </span><span class="hs-identifier">WindowEvent</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">WindowResize</span><span>
</span><span id="line-121"></span><span class="hs-identifier">processEvent</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-122"></span><span>
</span><span id="line-123"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">WORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Maybe</span><span> </span><span class="hs-identifier">BaseKey</span><span>
</span><span id="line-124"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">8</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">Backspace</span><span>
</span><span id="line-125"></span><span class="hs-pragma">{-# LINE 125 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-125"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">37</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">LeftKey</span><span>
</span><span id="line-126"></span><span class="hs-pragma">{-# LINE 126 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-126"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">39</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">RightKey</span><span>
</span><span id="line-127"></span><span class="hs-pragma">{-# LINE 127 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-127"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">38</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">UpKey</span><span>
</span><span id="line-128"></span><span class="hs-pragma">{-# LINE 128 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-128"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">40</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">DownKey</span><span>
</span><span id="line-129"></span><span class="hs-pragma">{-# LINE 129 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-129"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">46</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">Delete</span><span>
</span><span id="line-130"></span><span class="hs-pragma">{-# LINE 130 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-130"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">36</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">Home</span><span>
</span><span id="line-131"></span><span class="hs-pragma">{-# LINE 131 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-131"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">35</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">End</span><span>
</span><span id="line-132"></span><span class="hs-pragma">{-# LINE 132 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-132"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">33</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">PageUp</span><span>
</span><span id="line-133"></span><span class="hs-pragma">{-# LINE 133 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-133"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">34</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-identifier">PageDown</span><span>
</span><span id="line-134"></span><span class="hs-pragma">{-# LINE 134 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-134"></span><span class="hs-comment">-- The Windows console will return '\r' when return is pressed.</span><span>
</span><span id="line-135"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-special">(</span><span class="hs-number">13</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Just</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">KeyChar</span><span> </span><span class="hs-char">'\n'</span><span class="hs-special">)</span><span>
</span><span id="line-136"></span><span class="hs-pragma">{-# LINE 136 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-136"></span><span class="hs-comment">-- TODO: KillLine?</span><span>
</span><span id="line-137"></span><span class="hs-comment">-- TODO: function keys.</span><span>
</span><span id="line-138"></span><span class="hs-identifier">keyFromCode</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Nothing</span><span>
</span><span id="line-139"></span><span>
</span><span id="line-140"></span><span class="hs-keyword">data</span><span> </span><span class="hs-identifier">InputEvent</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">KeyEvent</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">keyDown</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">BOOL</span><span class="hs-special">,</span><span>
</span><span id="line-141"></span><span>                          </span><span class="hs-identifier">repeatCount</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">WORD</span><span class="hs-special">,</span><span>
</span><span id="line-142"></span><span>                          </span><span class="hs-identifier">virtualKeyCode</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">WORD</span><span class="hs-special">,</span><span>
</span><span id="line-143"></span><span>                          </span><span class="hs-identifier">virtualScanCode</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">WORD</span><span class="hs-special">,</span><span>
</span><span id="line-144"></span><span>                          </span><span class="hs-identifier">unicodeChar</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Char</span><span class="hs-special">,</span><span>
</span><span id="line-145"></span><span>                          </span><span class="hs-identifier">controlKeyState</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DWORD</span><span class="hs-special">}</span><span>
</span><span id="line-146"></span><span>            </span><span class="hs-comment">-- TODO: WINDOW_BUFFER_SIZE_RECORD</span><span>
</span><span id="line-147"></span><span>            </span><span class="hs-comment">-- I cant figure out how the user generates them.</span><span>
</span><span id="line-148"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">WindowEvent</span><span>
</span><span id="line-149"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">OtherEvent</span><span>
</span><span id="line-150"></span><span>                        </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-identifier">Show</span><span>
</span><span id="line-151"></span><span>
</span><span id="line-152"></span><span class="hs-identifier">peekEvent</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">InputEvent</span><span>
</span><span id="line-153"></span><span class="hs-identifier">peekEvent</span><span> </span><span class="hs-identifier">pRecord</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-154"></span><span>    </span><span class="hs-identifier">eventType</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">WORD</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">pRecord</span><span>
</span><span id="line-155"></span><span class="hs-pragma">{-# LINE 155 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-155"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">eventPtr</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">plusPtr</span><span class="hs-special">`</span><span> </span><span class="hs-number">4</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">pRecord</span><span>
</span><span id="line-156"></span><span class="hs-pragma">{-# LINE 156 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-156"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">eventType</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-157"></span><span>        </span><span class="hs-special">(</span><span class="hs-number">1</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">getKeyEvent</span><span> </span><span class="hs-identifier">eventPtr</span><span>
</span><span id="line-158"></span><span class="hs-pragma">{-# LINE 158 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-158"></span><span>        </span><span class="hs-special">(</span><span class="hs-number">4</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">WindowEvent</span><span>
</span><span id="line-159"></span><span class="hs-pragma">{-# LINE 159 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-159"></span><span>        </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">OtherEvent</span><span>
</span><span id="line-160"></span><span>
</span><span id="line-161"></span><span class="hs-identifier">readEvents</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">InputEvent</span><span class="hs-special">]</span><span>
</span><span id="line-162"></span><span class="hs-identifier">readEvents</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-163"></span><span>    </span><span class="hs-identifier">n</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getNumberOfEvents</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-164"></span><span>    </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">numEventsPtr</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-165"></span><span>        </span><span class="hs-identifier">allocaBytes</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">n</span><span> </span><span class="hs-operator">*</span><span> </span><span class="hs-special">(</span><span class="hs-number">20</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">pRecord</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-166"></span><span class="hs-pragma">{-# LINE 166 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-166"></span><span>            </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;ReadConsoleInput&quot;</span><span>
</span><span id="line-167"></span><span>                </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_ReadConsoleInput</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">pRecord</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">n</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">numEventsPtr</span><span>
</span><span id="line-168"></span><span>            </span><span class="hs-identifier">numRead</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">fmap</span><span> </span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">numEventsPtr</span><span>
</span><span id="line-169"></span><span>            </span><span class="hs-identifier">forM</span><span> </span><span class="hs-special">[</span><span class="hs-number">0</span><span class="hs-glyph">..</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">numRead</span><span class="hs-glyph">-</span><span class="hs-number">1</span><span class="hs-special">]</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">i</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekEvent</span><span>
</span><span id="line-170"></span><span>                </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">pRecord</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">plusPtr</span><span class="hs-special">`</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">i</span><span> </span><span class="hs-operator">*</span><span> </span><span class="hs-special">(</span><span class="hs-number">20</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-171"></span><span class="hs-pragma">{-# LINE 171 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-171"></span><span>
</span><span id="line-172"></span><span class="hs-identifier">getKeyEvent</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">InputEvent</span><span>
</span><span id="line-173"></span><span class="hs-identifier">getKeyEvent</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-174"></span><span>    </span><span class="hs-identifier">kDown'</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-175"></span><span class="hs-pragma">{-# LINE 175 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-175"></span><span>    </span><span class="hs-identifier">repeat'</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">4</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-176"></span><span class="hs-pragma">{-# LINE 176 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-176"></span><span>    </span><span class="hs-identifier">keyCode</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">6</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-177"></span><span class="hs-pragma">{-# LINE 177 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-177"></span><span>    </span><span class="hs-identifier">scanCode</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">8</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-178"></span><span class="hs-pragma">{-# LINE 178 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-178"></span><span>    </span><span class="hs-identifier">char</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CWchar</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">10</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-179"></span><span class="hs-pragma">{-# LINE 179 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-179"></span><span>    </span><span class="hs-identifier">state</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">12</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-180"></span><span class="hs-pragma">{-# LINE 180 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-180"></span><span>    </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">KeyEvent</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">keyDown</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">kDown'</span><span class="hs-special">,</span><span>
</span><span id="line-181"></span><span>                            </span><span class="hs-identifier">repeatCount</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">repeat'</span><span class="hs-special">,</span><span>
</span><span id="line-182"></span><span>                            </span><span class="hs-identifier">virtualKeyCode</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">keyCode</span><span class="hs-special">,</span><span>
</span><span id="line-183"></span><span>                            </span><span class="hs-identifier">virtualScanCode</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">scanCode</span><span class="hs-special">,</span><span>
</span><span id="line-184"></span><span>                            </span><span class="hs-identifier">unicodeChar</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-identifier">char</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-185"></span><span>                            </span><span class="hs-identifier">controlKeyState</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">state</span><span class="hs-special">}</span><span>
</span><span id="line-186"></span><span>
</span><span id="line-187"></span><span class="hs-keyword">data</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">coordX</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Int</span><span class="hs-special">}</span><span>
</span><span id="line-188"></span><span>                </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-identifier">Show</span><span>
</span><span id="line-189"></span><span>
</span><span id="line-190"></span><span class="hs-keyword">instance</span><span> </span><span class="hs-identifier">Storable</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-191"></span><span>    </span><span class="hs-identifier">sizeOf</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-number">4</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-192"></span><span class="hs-pragma">{-# LINE 192 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-192"></span><span>    </span><span class="hs-identifier">alignment</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-number">2</span><span class="hs-special">)</span><span>
</span><span id="line-193"></span><span class="hs-pragma">{-# LINE 193 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-193"></span><span>    </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-194"></span><span>        </span><span class="hs-identifier">cx</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CShort</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-195"></span><span class="hs-pragma">{-# LINE 195 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-195"></span><span>        </span><span class="hs-identifier">cy</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CShort</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">2</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-196"></span><span class="hs-pragma">{-# LINE 196 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-196"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">coordX</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-identifier">cx</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-identifier">cy</span><span class="hs-special">}</span><span>
</span><span id="line-197"></span><span>    </span><span class="hs-identifier">poke</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-198"></span><span>        </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">pokeByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">coordX</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CShort</span><span class="hs-special">)</span><span>
</span><span id="line-199"></span><span class="hs-pragma">{-# LINE 199 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-199"></span><span>        </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">pokeByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">2</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">coordY</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CShort</span><span class="hs-special">)</span><span>
</span><span id="line-200"></span><span class="hs-pragma">{-# LINE 200 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-200"></span><span>
</span><span id="line-201"></span><span>
</span><span id="line-202"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;haskeline_SetPosition&quot;</span><span>
</span><span id="line-203"></span><span>    </span><span class="hs-identifier">c_SetPosition</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-204"></span><span>
</span><span id="line-205"></span><span class="hs-identifier">setPosition</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-206"></span><span class="hs-identifier">setPosition</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">with</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;SetConsoleCursorPosition&quot;</span><span>
</span><span id="line-207"></span><span>                    </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">c_SetPosition</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-208"></span><span>
</span><span id="line-209"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h GetConsoleScreenBufferInfo&quot;</span><span>
</span><span id="line-210"></span><span>    </span><span class="hs-identifier">c_GetScreenBufferInfo</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-211"></span><span>
</span><span id="line-212"></span><span class="hs-identifier">getPosition</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Coord</span><span>
</span><span id="line-213"></span><span class="hs-identifier">getPosition</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withScreenBufferInfo</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-214"></span><span>    </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">4</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-215"></span><span class="hs-pragma">{-# LINE 215 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-215"></span><span>
</span><span id="line-216"></span><span class="hs-identifier">withScreenBufferInfo</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-217"></span><span class="hs-identifier">withScreenBufferInfo</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">allocaBytes</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-number">22</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-218"></span><span class="hs-pragma">{-# LINE 218 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-218"></span><span>                                </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">infoPtr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-219"></span><span>        </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;GetConsoleScreenBufferInfo&quot;</span><span>
</span><span id="line-220"></span><span>            </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_GetScreenBufferInfo</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">infoPtr</span><span>
</span><span id="line-221"></span><span>        </span><span class="hs-identifier">f</span><span> </span><span class="hs-identifier">infoPtr</span><span>
</span><span id="line-222"></span><span>
</span><span id="line-223"></span><span class="hs-identifier">getBufferSize</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Layout</span><span>
</span><span id="line-224"></span><span class="hs-identifier">getBufferSize</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withScreenBufferInfo</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-225"></span><span>    </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-226"></span><span class="hs-pragma">{-# LINE 226 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-226"></span><span>    </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">Layout</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">width</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">height</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">}</span><span>
</span><span id="line-227"></span><span>
</span><span id="line-228"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h WriteConsoleW&quot;</span><span> </span><span class="hs-identifier">c_WriteConsoleW</span><span>
</span><span id="line-229"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">TCHAR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-230"></span><span>
</span><span id="line-231"></span><span class="hs-identifier">writeConsole</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-232"></span><span class="hs-comment">-- For some reason, Wine returns False when WriteConsoleW is called on an empty</span><span>
</span><span id="line-233"></span><span class="hs-comment">-- string.  Easiest fix: just don't call that function.</span><span>
</span><span id="line-234"></span><span class="hs-identifier">writeConsole</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-string">&quot;&quot;</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-235"></span><span class="hs-identifier">writeConsole</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">str</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">writeConsole'</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">writeConsole</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">ys</span><span>
</span><span id="line-236"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-237"></span><span>    </span><span class="hs-special">(</span><span class="hs-identifier">xs</span><span class="hs-special">,</span><span class="hs-identifier">ys</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">splitAt</span><span> </span><span class="hs-identifier">limit</span><span> </span><span class="hs-identifier">str</span><span>
</span><span id="line-238"></span><span>    </span><span class="hs-comment">-- WriteConsoleW has a buffer limit which is documented as 32768 word8's,</span><span>
</span><span id="line-239"></span><span>    </span><span class="hs-comment">-- but bug reports from online suggest that the limit may be lower (~25000).</span><span>
</span><span id="line-240"></span><span>    </span><span class="hs-comment">-- To be safe, we pick a round number we know to be less than the limit.</span><span>
</span><span id="line-241"></span><span>    </span><span class="hs-identifier">limit</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">20000</span><span> </span><span class="hs-comment">-- known to be less than WriteConsoleW's buffer limit</span><span>
</span><span id="line-242"></span><span>    </span><span class="hs-identifier">writeConsole'</span><span>
</span><span id="line-243"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withCWStringLen</span><span> </span><span class="hs-identifier">xs</span><span>
</span><span id="line-244"></span><span>            </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="hs-identifier">t_arr</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">len</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">numWritten</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-245"></span><span>                    </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;WriteConsoleW&quot;</span><span>
</span><span id="line-246"></span><span>                        </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_WriteConsoleW</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">t_arr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">len</span><span class="hs-special">)</span><span>
</span><span id="line-247"></span><span>                                </span><span class="hs-identifier">numWritten</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-248"></span><span>
</span><span id="line-249"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h MessageBeep&quot;</span><span> </span><span class="hs-identifier">c_messageBeep</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">UINT</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-250"></span><span>
</span><span id="line-251"></span><span class="hs-identifier">messageBeep</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-252"></span><span class="hs-identifier">messageBeep</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">c_messageBeep</span><span> </span><span class="hs-identifier">simpleBeep</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-comment">-- intentionally ignore failures.</span><span>
</span><span id="line-253"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span class="hs-identifier">simpleBeep</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">0xffffffff</span><span>
</span><span id="line-254"></span><span>
</span><span id="line-255"></span><span>
</span><span id="line-256"></span><span class="hs-comment">----------</span><span>
</span><span id="line-257"></span><span class="hs-comment">-- Console mode</span><span>
</span><span id="line-258"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h GetConsoleMode&quot;</span><span> </span><span class="hs-identifier">c_GetConsoleMode</span><span>
</span><span id="line-259"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-260"></span><span>
</span><span id="line-261"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h SetConsoleMode&quot;</span><span> </span><span class="hs-identifier">c_SetConsoleMode</span><span>
</span><span id="line-262"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Bool</span><span>
</span><span id="line-263"></span><span>
</span><span id="line-264"></span><span class="hs-identifier">withWindowMode</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">MonadIO</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadMask</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">Handles</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-265"></span><span class="hs-identifier">withWindowMode</span><span> </span><span class="hs-identifier">hs</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-266"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hIn</span><span> </span><span class="hs-identifier">hs</span><span>
</span><span id="line-267"></span><span>    </span><span class="hs-identifier">bracket</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">getConsoleMode</span><span> </span><span class="hs-identifier">h</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">setConsoleMode</span><span> </span><span class="hs-identifier">h</span><span class="hs-special">)</span><span>
</span><span id="line-268"></span><span>            </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">setConsoleMode</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">m</span><span> </span><span class="hs-operator">.|.</span><span> </span><span class="hs-special">(</span><span class="hs-number">8</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">f</span><span>
</span><span id="line-269"></span><span class="hs-pragma">{-# LINE 269 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-269"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-270"></span><span>    </span><span class="hs-identifier">getConsoleMode</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-271"></span><span>            </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;GetConsoleMode&quot;</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_GetConsoleMode</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-272"></span><span>            </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-273"></span><span>    </span><span class="hs-identifier">setConsoleMode</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;SetConsoleMode&quot;</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_SetConsoleMode</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">m</span><span>
</span><span id="line-274"></span><span>
</span><span id="line-275"></span><span class="hs-comment">----------------------------</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- Drawing</span><span>
</span><span id="line-277"></span><span>
</span><span id="line-278"></span><span class="hs-keyword">data</span><span> </span><span class="hs-identifier">Handles</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Handles</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">hIn</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">hOut</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-279"></span><span>
</span><span id="line-280"></span><span class="hs-identifier">closeHandles</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handles</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-281"></span><span class="hs-identifier">closeHandles</span><span> </span><span class="hs-identifier">hs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">closeHandle</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">hIn</span><span> </span><span class="hs-identifier">hs</span><span class="hs-special">)</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">closeHandle</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">hOut</span><span> </span><span class="hs-identifier">hs</span><span class="hs-special">)</span><span>
</span><span id="line-282"></span><span>
</span><span id="line-283"></span><span class="hs-keyword">newtype</span><span> </span><span class="hs-identifier">Draw</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Draw</span><span> </span><span class="hs-special">{</span><span class="hs-identifier">runDraw</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">ReaderT</span><span> </span><span class="hs-identifier">Handles</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">}</span><span>
</span><span id="line-284"></span><span>    </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Functor</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Applicative</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">Monad</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadIO</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadReader</span><span> </span><span class="hs-identifier">Handles</span><span class="hs-special">,</span><span>
</span><span id="line-285"></span><span>              </span><span class="hs-identifier">MonadThrow</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadCatch</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadMask</span><span class="hs-special">)</span><span>
</span><span id="line-286"></span><span>
</span><span id="line-287"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">DrawM</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">forall</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">MonadIO</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadReader</span><span> </span><span class="hs-identifier">Layout</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">Draw</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-288"></span><span>
</span><span id="line-289"></span><span class="hs-keyword">instance</span><span> </span><span class="hs-identifier">MonadTrans</span><span> </span><span class="hs-identifier">Draw</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-290"></span><span>    </span><span class="hs-identifier">lift</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Draw</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">lift</span><span>
</span><span id="line-291"></span><span>
</span><span id="line-292"></span><span class="hs-identifier">getPos</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MonadIO</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">Draw</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">Coord</span><span>
</span><span id="line-293"></span><span class="hs-identifier">getPos</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">asks</span><span> </span><span class="hs-identifier">hOut</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">getPosition</span><span>
</span><span id="line-294"></span><span>
</span><span id="line-295"></span><span class="hs-identifier">setPos</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DrawM</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-296"></span><span class="hs-identifier">setPos</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-297"></span><span>    </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">asks</span><span> </span><span class="hs-identifier">hOut</span><span>
</span><span id="line-298"></span><span>    </span><span class="hs-comment">-- SetPosition will fail if you give it something out of bounds of</span><span>
</span><span id="line-299"></span><span>    </span><span class="hs-comment">-- the window buffer (i.e., the input line doesn't fit in the window).</span><span>
</span><span id="line-300"></span><span>    </span><span class="hs-comment">-- So we do a simple guard against that uncommon case.</span><span>
</span><span id="line-301"></span><span>    </span><span class="hs-comment">-- However, we don't throw away the x coord since it produces sensible</span><span>
</span><span id="line-302"></span><span>    </span><span class="hs-comment">-- results for some cases.</span><span>
</span><span id="line-303"></span><span>    </span><span class="hs-identifier">maxY</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">liftM</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">subtract</span><span> </span><span class="hs-number">1</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">asks</span><span> </span><span class="hs-identifier">height</span><span>
</span><span id="line-304"></span><span>    </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">setPosition</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">max</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">min</span><span> </span><span class="hs-identifier">maxY</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-305"></span><span>
</span><span id="line-306"></span><span class="hs-identifier">printText</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MonadIO</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Draw</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-307"></span><span class="hs-identifier">printText</span><span> </span><span class="hs-identifier">txt</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-308"></span><span>    </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">asks</span><span> </span><span class="hs-identifier">hOut</span><span>
</span><span id="line-309"></span><span>    </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">writeConsole</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">txt</span><span class="hs-special">)</span><span>
</span><span id="line-310"></span><span>
</span><span id="line-311"></span><span class="hs-identifier">printAfter</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Grapheme</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DrawM</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-312"></span><span class="hs-identifier">printAfter</span><span> </span><span class="hs-identifier">gs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-313"></span><span>    </span><span class="hs-comment">-- NOTE: you may be tempted to write</span><span>
</span><span id="line-314"></span><span>    </span><span class="hs-comment">-- do {p &lt;- getPos; printText (...); setPos p}</span><span>
</span><span id="line-315"></span><span>    </span><span class="hs-comment">-- Unfortunately, that would be WRONG, because if printText wraps</span><span>
</span><span id="line-316"></span><span>    </span><span class="hs-comment">-- a line at the bottom of the window, causing the window to scroll,</span><span>
</span><span id="line-317"></span><span>    </span><span class="hs-comment">-- then the old value of p will be incorrect.</span><span>
</span><span id="line-318"></span><span>    </span><span class="hs-identifier">printText</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">graphemesToString</span><span> </span><span class="hs-identifier">gs</span><span class="hs-special">)</span><span>
</span><span id="line-319"></span><span>    </span><span class="hs-identifier">movePosLeft</span><span> </span><span class="hs-identifier">gs</span><span>
</span><span id="line-320"></span><span>
</span><span id="line-321"></span><span class="hs-identifier">drawLineDiffWin</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">LineChars</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LineChars</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DrawM</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-322"></span><span class="hs-identifier">drawLineDiffWin</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">xs1</span><span class="hs-special">,</span><span class="hs-identifier">ys1</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">xs2</span><span class="hs-special">,</span><span class="hs-identifier">ys2</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">matchInit</span><span> </span><span class="hs-identifier">xs1</span><span> </span><span class="hs-identifier">xs2</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-323"></span><span>    </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">ys1</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">ys2</span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-324"></span><span>    </span><span class="hs-special">(</span><span class="hs-identifier">xs1'</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">xs1'</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">ys1</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">ys2</span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">movePosLeft</span><span> </span><span class="hs-identifier">xs1'</span><span>
</span><span id="line-325"></span><span>    </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-identifier">xs2'</span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">ys1</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-identifier">xs2'</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">ys2</span><span>    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">movePosRight</span><span> </span><span class="hs-identifier">xs2'</span><span>
</span><span id="line-326"></span><span>    </span><span class="hs-special">(</span><span class="hs-identifier">xs1'</span><span class="hs-special">,</span><span class="hs-identifier">xs2'</span><span class="hs-special">)</span><span>                         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-327"></span><span>        </span><span class="hs-identifier">movePosLeft</span><span> </span><span class="hs-identifier">xs1'</span><span>
</span><span id="line-328"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">gsWidth</span><span> </span><span class="hs-identifier">xs1'</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-identifier">gsWidth</span><span> </span><span class="hs-identifier">ys1</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">gsWidth</span><span> </span><span class="hs-identifier">xs2'</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-identifier">gsWidth</span><span> </span><span class="hs-identifier">ys2</span><span class="hs-special">)</span><span>
</span><span id="line-329"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">deadText</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">stringToGraphemes</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">replicate</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-char">' '</span><span>
</span><span id="line-330"></span><span>        </span><span class="hs-identifier">printText</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">graphemesToString</span><span> </span><span class="hs-identifier">xs2'</span><span class="hs-special">)</span><span>
</span><span id="line-331"></span><span>        </span><span class="hs-identifier">printAfter</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ys2</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">deadText</span><span class="hs-special">)</span><span>
</span><span id="line-332"></span><span>
</span><span id="line-333"></span><span class="hs-identifier">movePosRight</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">movePosLeft</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">Grapheme</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DrawM</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-334"></span><span class="hs-identifier">movePosRight</span><span> </span><span class="hs-identifier">str</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-335"></span><span>    </span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getPos</span><span>
</span><span id="line-336"></span><span>    </span><span class="hs-identifier">w</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">asks</span><span> </span><span class="hs-identifier">width</span><span>
</span><span id="line-337"></span><span>    </span><span class="hs-identifier">setPos</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">moveCoord</span><span> </span><span class="hs-identifier">w</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">str</span><span>
</span><span id="line-338"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-339"></span><span>    </span><span class="hs-identifier">moveCoord</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-340"></span><span>    </span><span class="hs-identifier">moveCoord</span><span> </span><span class="hs-identifier">w</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">cs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">splitAtWidth</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">w</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-identifier">p</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">cs</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-341"></span><span>                        </span><span class="hs-special">(</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-identifier">len</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">len</span><span> </span><span class="hs-operator">&lt;</span><span> </span><span class="hs-identifier">w</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-comment">-- stayed on same line</span><span>
</span><span id="line-342"></span><span>                            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-identifier">p</span><span class="hs-special">,</span><span>
</span><span id="line-343"></span><span>                                       </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-identifier">len</span><span>
</span><span id="line-344"></span><span>                                     </span><span class="hs-special">}</span><span>
</span><span id="line-345"></span><span>                        </span><span class="hs-special">(</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span class="hs-identifier">cs'</span><span class="hs-special">,</span><span class="hs-identifier">_</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- moved to next line</span><span>
</span><span id="line-346"></span><span>                            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">moveCoord</span><span> </span><span class="hs-identifier">w</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-347"></span><span>                                            </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-number">1</span><span class="hs-special">,</span><span>
</span><span id="line-348"></span><span>                                            </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-349"></span><span>                                           </span><span class="hs-special">}</span><span> </span><span class="hs-identifier">cs'</span><span>
</span><span id="line-350"></span><span>
</span><span id="line-351"></span><span class="hs-identifier">movePosLeft</span><span> </span><span class="hs-identifier">str</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-352"></span><span>    </span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getPos</span><span>
</span><span id="line-353"></span><span>    </span><span class="hs-identifier">w</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">asks</span><span> </span><span class="hs-identifier">width</span><span>
</span><span id="line-354"></span><span>    </span><span class="hs-identifier">setPos</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">moveCoord</span><span> </span><span class="hs-identifier">w</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">str</span><span>
</span><span id="line-355"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-356"></span><span>    </span><span class="hs-identifier">moveCoord</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">p</span><span>
</span><span id="line-357"></span><span>    </span><span class="hs-identifier">moveCoord</span><span> </span><span class="hs-identifier">w</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-identifier">cs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">splitAtWidth</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">coordX</span><span> </span><span class="hs-identifier">p</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">cs</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-358"></span><span>                        </span><span class="hs-special">(</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-identifier">len</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- stayed on same line</span><span>
</span><span id="line-359"></span><span>                            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-identifier">p</span><span class="hs-special">,</span><span>
</span><span id="line-360"></span><span>                                       </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-identifier">len</span><span>
</span><span id="line-361"></span><span>                                     </span><span class="hs-special">}</span><span>
</span><span id="line-362"></span><span>                        </span><span class="hs-special">(</span><span class="hs-identifier">_</span><span class="hs-special">,</span><span class="hs-identifier">_</span><span class="hs-glyph">:</span><span class="hs-identifier">cs'</span><span class="hs-special">,</span><span class="hs-identifier">_</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- moved to previous line</span><span>
</span><span id="line-363"></span><span>                            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">moveCoord</span><span> </span><span class="hs-identifier">w</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-364"></span><span>                                            </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">coordY</span><span> </span><span class="hs-identifier">p</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-number">1</span><span class="hs-special">,</span><span>
</span><span id="line-365"></span><span>                                            </span><span class="hs-identifier">coordX</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">w</span><span class="hs-glyph">-</span><span class="hs-number">1</span><span>
</span><span id="line-366"></span><span>                                           </span><span class="hs-special">}</span><span> </span><span class="hs-identifier">cs'</span><span>
</span><span id="line-367"></span><span>
</span><span id="line-368"></span><span class="hs-identifier">crlf</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">String</span><span>
</span><span id="line-369"></span><span class="hs-identifier">crlf</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-string">&quot;\r\n&quot;</span><span>
</span><span id="line-370"></span><span>
</span><span id="line-371"></span><span class="hs-keyword">instance</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">MonadMask</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadIO</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadReader</span><span> </span><span class="hs-identifier">Layout</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">Term</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Draw</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-372"></span><span>    </span><span class="hs-identifier">drawLineDiff</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">xs1</span><span class="hs-special">,</span><span class="hs-identifier">ys1</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">xs2</span><span class="hs-special">,</span><span class="hs-identifier">ys2</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span>
</span><span id="line-373"></span><span>        </span><span class="hs-identifier">fixEsc</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">filter</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-operator">/=</span><span> </span><span class="hs-char">'\ESC'</span><span class="hs-special">)</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">baseChar</span><span class="hs-special">)</span><span>
</span><span id="line-374"></span><span>        </span><span class="hs-keyword">in</span><span> </span><span class="hs-identifier">drawLineDiffWin</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fixEsc</span><span> </span><span class="hs-identifier">xs1</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fixEsc</span><span> </span><span class="hs-identifier">ys1</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fixEsc</span><span> </span><span class="hs-identifier">xs2</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fixEsc</span><span> </span><span class="hs-identifier">ys2</span><span class="hs-special">)</span><span>
</span><span id="line-375"></span><span>    </span><span class="hs-comment">-- TODO now that we capture resize events.</span><span>
</span><span id="line-376"></span><span>    </span><span class="hs-comment">-- first, looks like the cursor stays on the same line but jumps</span><span>
</span><span id="line-377"></span><span>    </span><span class="hs-comment">-- to the beginning if cut off.</span><span>
</span><span id="line-378"></span><span>    </span><span class="hs-identifier">reposition</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-379"></span><span>
</span><span id="line-380"></span><span>    </span><span class="hs-identifier">printLines</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-381"></span><span>    </span><span class="hs-identifier">printLines</span><span> </span><span class="hs-identifier">ls</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">printText</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">intercalate</span><span> </span><span class="hs-identifier">crlf</span><span> </span><span class="hs-identifier">ls</span><span> </span><span class="hs-operator">++</span><span> </span><span class="hs-identifier">crlf</span><span>
</span><span id="line-382"></span><span>
</span><span id="line-383"></span><span>    </span><span class="hs-identifier">clearLayout</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">clearScreen</span><span>
</span><span id="line-384"></span><span>
</span><span id="line-385"></span><span>    </span><span class="hs-identifier">moveToNextLine</span><span> </span><span class="hs-identifier">s</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-386"></span><span>        </span><span class="hs-identifier">movePosRight</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">snd</span><span> </span><span class="hs-identifier">s</span><span class="hs-special">)</span><span>
</span><span id="line-387"></span><span>        </span><span class="hs-identifier">printText</span><span> </span><span class="hs-string">&quot;\r\n&quot;</span><span> </span><span class="hs-comment">-- make the console take care of creating a new line</span><span>
</span><span id="line-388"></span><span>
</span><span id="line-389"></span><span>    </span><span class="hs-identifier">ringBell</span><span> </span><span class="hs-identifier">True</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-identifier">messageBeep</span><span>
</span><span id="line-390"></span><span>    </span><span class="hs-identifier">ringBell</span><span> </span><span class="hs-identifier">False</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- TODO</span><span>
</span><span id="line-391"></span><span>
</span><span id="line-392"></span><span class="hs-identifier">win32TermStdin</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MaybeT</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">RunTerm</span><span>
</span><span id="line-393"></span><span class="hs-identifier">win32TermStdin</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-394"></span><span>    </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">hIsTerminalDevice</span><span> </span><span class="hs-identifier">stdin</span><span class="hs-special">)</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">guard</span><span>
</span><span id="line-395"></span><span>    </span><span class="hs-identifier">win32Term</span><span>
</span><span id="line-396"></span><span>
</span><span id="line-397"></span><span class="hs-identifier">win32Term</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MaybeT</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">RunTerm</span><span>
</span><span id="line-398"></span><span class="hs-identifier">win32Term</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-399"></span><span>    </span><span class="hs-identifier">hs</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">consoleHandles</span><span>
</span><span id="line-400"></span><span>    </span><span class="hs-identifier">ch</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-identifier">newTChanIO</span><span>
</span><span id="line-401"></span><span>    </span><span class="hs-identifier">fileRT</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">fileRunTerm</span><span> </span><span class="hs-identifier">stdin</span><span>
</span><span id="line-402"></span><span>    </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">fileRT</span><span>
</span><span id="line-403"></span><span>      </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">termOps</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Left</span><span> </span><span class="hs-identifier">TermOps</span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-404"></span><span>          </span><span class="hs-identifier">getLayout</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">getBufferSize</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">hOut</span><span> </span><span class="hs-identifier">hs</span><span class="hs-special">)</span><span>
</span><span id="line-405"></span><span>          </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">withGetEvent</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withWindowMode</span><span> </span><span class="hs-identifier">hs</span><span>
</span><span id="line-406"></span><span>                              </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">win32WithEvent</span><span> </span><span class="hs-identifier">hs</span><span> </span><span class="hs-identifier">ch</span><span>
</span><span id="line-407"></span><span>          </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">saveUnusedKeys</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">saveKeys</span><span> </span><span class="hs-identifier">ch</span><span>
</span><span id="line-408"></span><span>          </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">evalTerm</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">EvalTerm</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">runReaderT'</span><span> </span><span class="hs-identifier">hs</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">runDraw</span><span class="hs-special">)</span><span>
</span><span id="line-409"></span><span>                              </span><span class="hs-special">(</span><span class="hs-identifier">Draw</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">lift</span><span class="hs-special">)</span><span>
</span><span id="line-410"></span><span>          </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">externalPrint</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">atomically</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">writeTChan</span><span> </span><span class="hs-identifier">ch</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">ExternalPrint</span><span>
</span><span id="line-411"></span><span>          </span><span class="hs-special">}</span><span>
</span><span id="line-412"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">closeTerm</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-413"></span><span>          </span><span class="hs-identifier">flushEventQueue</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">putStrOut</span><span> </span><span class="hs-identifier">fileRT</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">ch</span><span>
</span><span id="line-414"></span><span>          </span><span class="hs-identifier">closeHandles</span><span> </span><span class="hs-identifier">hs</span><span>
</span><span id="line-415"></span><span>      </span><span class="hs-special">}</span><span>
</span><span id="line-416"></span><span>
</span><span id="line-417"></span><span class="hs-identifier">win32WithEvent</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">MonadIO</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">Handles</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">TChan</span><span> </span><span class="hs-identifier">Event</span><span>
</span><span id="line-418"></span><span>                                        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">Event</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-419"></span><span class="hs-identifier">win32WithEvent</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">eventChan</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">getEvent</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">hIn</span><span> </span><span class="hs-identifier">h</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">eventChan</span><span>
</span><span id="line-420"></span><span>
</span><span id="line-421"></span><span class="hs-comment">-- stdin is not a terminal, but we still need to check the right way to output unicode to stdout.</span><span>
</span><span id="line-422"></span><span class="hs-identifier">fileRunTerm</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">RunTerm</span><span>
</span><span id="line-423"></span><span class="hs-identifier">fileRunTerm</span><span> </span><span class="hs-identifier">h_in</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-424"></span><span>    </span><span class="hs-identifier">putter</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">putOut</span><span>
</span><span id="line-425"></span><span>    </span><span class="hs-identifier">cp</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getCodePage</span><span>
</span><span id="line-426"></span><span>    </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">RunTerm</span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-427"></span><span>                    </span><span class="hs-identifier">closeTerm</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-428"></span><span>                    </span><span class="hs-identifier">putStrOut</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">putter</span><span class="hs-special">,</span><span>
</span><span id="line-429"></span><span>                    </span><span class="hs-identifier">wrapInterrupt</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withCtrlCHandler</span><span class="hs-special">,</span><span>
</span><span id="line-430"></span><span>                    </span><span class="hs-identifier">termOps</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Right</span><span> </span><span class="hs-identifier">FileOps</span><span>
</span><span id="line-431"></span><span>                                </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">withoutInputEcho</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hWithoutInputEcho</span><span> </span><span class="hs-identifier">h_in</span><span>
</span><span id="line-432"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">wrapFileInput</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hWithBinaryMode</span><span> </span><span class="hs-identifier">h_in</span><span>
</span><span id="line-433"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">getLocaleChar</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">getMultiByteChar</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-identifier">h_in</span><span>
</span><span id="line-434"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">maybeReadNewline</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hMaybeReadNewline</span><span> </span><span class="hs-identifier">h_in</span><span>
</span><span id="line-435"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">getLocaleLine</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">hGetLocaleLine</span><span> </span><span class="hs-identifier">h_in</span><span>
</span><span id="line-436"></span><span>                                            </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">.</span><span> </span><span class="hs-identifier">codePageToUnicode</span><span> </span><span class="hs-identifier">cp</span><span>
</span><span id="line-437"></span><span>                                </span><span class="hs-special">}</span><span>
</span><span id="line-438"></span><span>
</span><span id="line-439"></span><span>                    </span><span class="hs-special">}</span><span>
</span><span id="line-440"></span><span>
</span><span id="line-441"></span><span class="hs-comment">-- On Windows, Unicode written to the console must be written with the WriteConsole API call.</span><span>
</span><span id="line-442"></span><span class="hs-comment">-- And to make the API cross-platform consistent, Unicode to a file should be UTF-8.</span><span>
</span><span id="line-443"></span><span class="hs-identifier">putOut</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-444"></span><span class="hs-identifier">putOut</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-445"></span><span>    </span><span class="hs-identifier">outIsTerm</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">hIsTerminalDevice</span><span> </span><span class="hs-identifier">stdout</span><span>
</span><span id="line-446"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">outIsTerm</span><span>
</span><span id="line-447"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-448"></span><span>            </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getStdHandle</span><span> </span><span class="hs-identifier">sTD_OUTPUT_HANDLE</span><span>
</span><span id="line-449"></span><span>            </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">writeConsole</span><span> </span><span class="hs-identifier">h</span><span class="hs-special">)</span><span>
</span><span id="line-450"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-451"></span><span>            </span><span class="hs-identifier">cp</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getCodePage</span><span>
</span><span id="line-452"></span><span>            </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">str</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">unicodeToCodePage</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-identifier">str</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-identifier">B.putStr</span><span> </span><span class="hs-operator">&gt;&gt;</span><span> </span><span class="hs-identifier">hFlush</span><span> </span><span class="hs-identifier">stdout</span><span>
</span><span id="line-453"></span><span>
</span><span id="line-454"></span><span>
</span><span id="line-455"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">Handler</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-456"></span><span>
</span><span id="line-457"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;wrapper&quot;</span><span> </span><span class="hs-identifier">wrapHandler</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">Handler</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">FunPtr</span><span> </span><span class="hs-identifier">Handler</span><span class="hs-special">)</span><span>
</span><span id="line-458"></span><span>
</span><span id="line-459"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;windows.h SetConsoleCtrlHandler&quot;</span><span> </span><span class="hs-identifier">c_SetConsoleCtrlHandler</span><span>
</span><span id="line-460"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">FunPtr</span><span> </span><span class="hs-identifier">Handler</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">BOOL</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-461"></span><span>
</span><span id="line-462"></span><span class="hs-comment">-- sets the tv to True when ctrl-c is pressed.</span><span>
</span><span id="line-463"></span><span class="hs-identifier">withCtrlCHandler</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">MonadMask</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">MonadIO</span><span> </span><span class="hs-identifier">m</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">m</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-464"></span><span class="hs-identifier">withCtrlCHandler</span><span> </span><span class="hs-identifier">f</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">bracket</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-465"></span><span>                                    </span><span class="hs-identifier">tid</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">myThreadId</span><span>
</span><span id="line-466"></span><span>                                    </span><span class="hs-identifier">fp</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">wrapHandler</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">handler</span><span> </span><span class="hs-identifier">tid</span><span class="hs-special">)</span><span>
</span><span id="line-467"></span><span>                                </span><span class="hs-comment">-- don't fail if we can't set the ctrl-c handler</span><span>
</span><span id="line-468"></span><span>                                </span><span class="hs-comment">-- for example, we might not be attached to a console?</span><span>
</span><span id="line-469"></span><span>                                    </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">c_SetConsoleCtrlHandler</span><span> </span><span class="hs-identifier">fp</span><span> </span><span class="hs-identifier">True</span><span>
</span><span id="line-470"></span><span>                                    </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">fp</span><span class="hs-special">)</span><span>
</span><span id="line-471"></span><span>                                </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">fp</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_SetConsoleCtrlHandler</span><span> </span><span class="hs-identifier">fp</span><span> </span><span class="hs-identifier">False</span><span class="hs-special">)</span><span>
</span><span id="line-472"></span><span>                                </span><span class="hs-special">(</span><span class="hs-identifier">const</span><span> </span><span class="hs-identifier">f</span><span class="hs-special">)</span><span>
</span><span id="line-473"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-474"></span><span>    </span><span class="hs-identifier">handler</span><span> </span><span class="hs-identifier">tid</span><span> </span><span class="hs-special">(</span><span class="hs-number">0</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-475"></span><span class="hs-pragma">{-# LINE 475 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-475"></span><span>        </span><span class="hs-identifier">throwTo</span><span> </span><span class="hs-identifier">tid</span><span> </span><span class="hs-identifier">Interrupt</span><span>
</span><span id="line-476"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">True</span><span>
</span><span id="line-477"></span><span>    </span><span class="hs-identifier">handler</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">False</span><span>
</span><span id="line-478"></span><span>
</span><span id="line-479"></span><span>
</span><span id="line-480"></span><span>
</span><span id="line-481"></span><span class="hs-comment">------------------------</span><span>
</span><span id="line-482"></span><span class="hs-comment">-- Multi-byte conversion</span><span>
</span><span id="line-483"></span><span>
</span><span id="line-484"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;WideCharToMultiByte&quot;</span><span> </span><span class="hs-identifier">wideCharToMultiByte</span><span>
</span><span id="line-485"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CodePage</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPCWSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPCSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span>
</span><span id="line-486"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPCSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPBOOL</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">CInt</span><span>
</span><span id="line-487"></span><span>
</span><span id="line-488"></span><span class="hs-identifier">unicodeToCodePage</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CodePage</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">String</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">B.ByteString</span><span>
</span><span id="line-489"></span><span class="hs-identifier">unicodeToCodePage</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-identifier">wideStr</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withCWStringLen</span><span> </span><span class="hs-identifier">wideStr</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="hs-identifier">wideBuff</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">wideLen</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-490"></span><span>    </span><span class="hs-comment">-- first, ask for the length without filling the buffer.</span><span>
</span><span id="line-491"></span><span>    </span><span class="hs-identifier">outSize</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">wideCharToMultiByte</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">wideBuff</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">wideLen</span><span class="hs-special">)</span><span>
</span><span id="line-492"></span><span>                    </span><span class="hs-identifier">nullPtr</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">nullPtr</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-493"></span><span>    </span><span class="hs-comment">-- then, actually perform the encoding.</span><span>
</span><span id="line-494"></span><span>    </span><span class="hs-identifier">createAndTrim</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-identifier">outSize</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">outBuff</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-495"></span><span>        </span><span class="hs-identifier">fmap</span><span> </span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">wideCharToMultiByte</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">wideBuff</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">wideLen</span><span class="hs-special">)</span><span>
</span><span id="line-496"></span><span>                    </span><span class="hs-special">(</span><span class="hs-identifier">castPtr</span><span> </span><span class="hs-identifier">outBuff</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">outSize</span><span> </span><span class="hs-identifier">nullPtr</span><span> </span><span class="hs-identifier">nullPtr</span><span>
</span><span id="line-497"></span><span>
</span><span id="line-498"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;MultiByteToWideChar&quot;</span><span> </span><span class="hs-identifier">multiByteToWideChar</span><span>
</span><span id="line-499"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CodePage</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPCSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">LPWSTR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">CInt</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">CInt</span><span>
</span><span id="line-500"></span><span>
</span><span id="line-501"></span><span class="hs-identifier">codePageToUnicode</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CodePage</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">B.ByteString</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">String</span><span>
</span><span id="line-502"></span><span class="hs-identifier">codePageToUnicode</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-identifier">bs</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">B.useAsCStringLen</span><span> </span><span class="hs-identifier">bs</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="hs-identifier">inBuff</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">inLen</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-503"></span><span>    </span><span class="hs-comment">-- first ask for the size without filling the buffer.</span><span>
</span><span id="line-504"></span><span>    </span><span class="hs-identifier">outSize</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">multiByteToWideChar</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">inBuff</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">inLen</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">nullPtr</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-505"></span><span>    </span><span class="hs-comment">-- then, actually perform the decoding.</span><span>
</span><span id="line-506"></span><span>    </span><span class="hs-identifier">allocaArray0</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-identifier">outSize</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">outBuff</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-507"></span><span>    </span><span class="hs-identifier">outSize'</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">multiByteToWideChar</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-identifier">inBuff</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">inLen</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">outBuff</span><span> </span><span class="hs-identifier">outSize</span><span>
</span><span id="line-508"></span><span>    </span><span class="hs-identifier">peekCWStringLen</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">outBuff</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-identifier">outSize'</span><span class="hs-special">)</span><span>
</span><span id="line-509"></span><span>
</span><span id="line-510"></span><span>
</span><span id="line-511"></span><span class="hs-identifier">getCodePage</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">CodePage</span><span>
</span><span id="line-512"></span><span class="hs-identifier">getCodePage</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-513"></span><span>    </span><span class="hs-identifier">conCP</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">getConsoleCP</span><span>
</span><span id="line-514"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">conCP</span><span> </span><span class="hs-operator">&gt;</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-515"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">conCP</span><span>
</span><span id="line-516"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">getACP</span><span>
</span><span id="line-517"></span><span>
</span><span id="line-518"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-string">&quot;IsDBCSLeadByteEx&quot;</span><span> </span><span class="hs-identifier">c_IsDBCSLeadByteEx</span><span>
</span><span id="line-519"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CodePage</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">BYTE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-520"></span><span>
</span><span id="line-521"></span><span class="hs-identifier">getMultiByteChar</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">CodePage</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Handle</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">MaybeT</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">Char</span><span>
</span><span id="line-522"></span><span class="hs-identifier">getMultiByteChar</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-523"></span><span>        </span><span class="hs-identifier">b1</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">hGetByte</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-524"></span><span>        </span><span class="hs-identifier">bs</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-identifier">c_IsDBCSLeadByteEx</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-identifier">b1</span><span>
</span><span id="line-525"></span><span>                </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">hGetByte</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-operator">&gt;&gt;=</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">b2</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">b1</span><span class="hs-special">,</span><span class="hs-identifier">b2</span><span class="hs-special">]</span><span>
</span><span id="line-526"></span><span>                </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">[</span><span class="hs-identifier">b1</span><span class="hs-special">]</span><span>
</span><span id="line-527"></span><span>        </span><span class="hs-identifier">cs</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">codePageToUnicode</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">B.pack</span><span> </span><span class="hs-identifier">bs</span><span class="hs-special">)</span><span>
</span><span id="line-528"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">cs</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-529"></span><span>            </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">getMultiByteChar</span><span> </span><span class="hs-identifier">cp</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-530"></span><span>            </span><span class="hs-special">(</span><span class="hs-identifier">c</span><span class="hs-glyph">:</span><span class="hs-identifier">_</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-identifier">c</span><span>
</span><span id="line-531"></span><span>
</span><span id="line-532"></span><span class="hs-comment">----------------------------------</span><span>
</span><span id="line-533"></span><span class="hs-comment">-- Clearing screen</span><span>
</span><span id="line-534"></span><span class="hs-comment">-- WriteConsole has a limit of ~20,000-30000 characters, which is</span><span>
</span><span id="line-535"></span><span class="hs-comment">-- less than a 200x200 window, for example.</span><span>
</span><span id="line-536"></span><span class="hs-comment">-- So we'll use other Win32 functions to clear the screen.</span><span>
</span><span id="line-537"></span><span>
</span><span id="line-538"></span><span class="hs-identifier">getAttribute</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">WORD</span><span>
</span><span id="line-539"></span><span class="hs-identifier">getAttribute</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">withScreenBufferInfo</span><span> </span><span class="hs-operator">$</span><span>
</span><span id="line-540"></span><span>    </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">8</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-541"></span><span class="hs-pragma">{-# LINE 541 &quot;libraries\\haskeline\\System\\Console\\Haskeline\\Backend\\Win32.hsc&quot; #-}</span><span>
</span><span id="line-541"></span><span>
</span><span id="line-542"></span><span class="hs-identifier">fillConsoleChar</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Char</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-543"></span><span class="hs-identifier">fillConsoleChar</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-identifier">n</span><span> </span><span class="hs-identifier">start</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">with</span><span> </span><span class="hs-identifier">start</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">startPtr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">numWritten</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-544"></span><span>    </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;FillConsoleOutputCharacter&quot;</span><span>
</span><span id="line-545"></span><span>        </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_FillConsoleCharacter</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">fromEnum</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">)</span><span>
</span><span id="line-546"></span><span>            </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">n</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">startPtr</span><span> </span><span class="hs-identifier">numWritten</span><span>
</span><span id="line-547"></span><span>
</span><span id="line-548"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;haskeline_FillConsoleCharacter&quot;</span><span> </span><span class="hs-identifier">c_FillConsoleCharacter</span><span>
</span><span id="line-549"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">TCHAR</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-550"></span><span>
</span><span id="line-551"></span><span class="hs-identifier">fillConsoleAttribute</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">WORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-552"></span><span class="hs-identifier">fillConsoleAttribute</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">a</span><span> </span><span class="hs-identifier">n</span><span> </span><span class="hs-identifier">start</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">with</span><span> </span><span class="hs-identifier">start</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">startPtr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">alloca</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">numWritten</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-553"></span><span>    </span><span class="hs-identifier">failIfFalse_</span><span> </span><span class="hs-string">&quot;FillConsoleOutputAttribute&quot;</span><span>
</span><span id="line-554"></span><span>        </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">c_FillConsoleAttribute</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">a</span><span>
</span><span id="line-555"></span><span>            </span><span class="hs-special">(</span><span class="hs-identifier">toEnum</span><span> </span><span class="hs-identifier">n</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">startPtr</span><span> </span><span class="hs-identifier">numWritten</span><span>
</span><span id="line-556"></span><span>
</span><span id="line-557"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-string">&quot;haskeline_FillConsoleAttribute&quot;</span><span> </span><span class="hs-identifier">c_FillConsoleAttribute</span><span>
</span><span id="line-558"></span><span>    </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HANDLE</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">WORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">DWORD</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-559"></span><span>
</span><span id="line-560"></span><span class="hs-identifier">clearScreen</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">DrawM</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-561"></span><span class="hs-identifier">clearScreen</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-562"></span><span>    </span><span class="hs-identifier">lay</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">ask</span><span>
</span><span id="line-563"></span><span>    </span><span class="hs-identifier">h</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">asks</span><span> </span><span class="hs-identifier">hOut</span><span>
</span><span id="line-564"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">windowSize</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">width</span><span> </span><span class="hs-identifier">lay</span><span> </span><span class="hs-operator">*</span><span> </span><span class="hs-identifier">height</span><span> </span><span class="hs-identifier">lay</span><span>
</span><span id="line-565"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">origin</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Coord</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-566"></span><span>    </span><span class="hs-identifier">attr</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">getAttribute</span><span> </span><span class="hs-identifier">h</span><span>
</span><span id="line-567"></span><span>    </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">fillConsoleChar</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-char">' '</span><span> </span><span class="hs-identifier">windowSize</span><span> </span><span class="hs-identifier">origin</span><span>
</span><span id="line-568"></span><span>    </span><span class="hs-identifier">liftIO</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">fillConsoleAttribute</span><span> </span><span class="hs-identifier">h</span><span> </span><span class="hs-identifier">attr</span><span> </span><span class="hs-identifier">windowSize</span><span> </span><span class="hs-identifier">origin</span><span>
</span><span id="line-569"></span><span>    </span><span class="hs-identifier">setPos</span><span> </span><span class="hs-identifier">origin</span><span>
</span><span id="line-570"></span></pre></body></html>